<template>
  <div  v-loading="this.loading" >
    <form-edit v-if="isEdit=='edit'" @clickisEdit="clickisEdit" :taskId="taskId" :pDocUnid="this.docUnid" :processKey="this.processKey"></form-edit>
    <form-read v-else-if="isEdit=='read'" @clickisEdit="clickisEdit" :pDocUnid="this.docUnid"></form-read>
    <error-view v-else-if="isEdit=='error'" ></error-view>
    <loading v-else></loading>
  </div>
</template>

<script>
  import formRead from '@/views/oa/basic/fwgl/form/formRead.vue'
  import formEdit from '@/views/oa/basic/fwgl/form/formEdit.vue'
  import errorView from '@/views/error/fwgl/401.vue'
  import loading from '@/views/error/fwgl/blank_.vue'
  import{ judgeDocType }from '@/api/fwgl/form.js'
  export default {
    data() {
      return {
        //表单类型
        isEdit:null,
        //文档id
        docUnid:'',
        //任务id
        taskId:null,
        //流程key
        processKey:'',
        loading:true
      }
    },
    components:{
      formRead,
      formEdit,
      errorView,
      loading
    },
    methods:{
      clickisEdit(data){
        this.isEdit = data
      }
    },
    created() {
      //let taskId = this.$route.query.taskId;
      let taskId = this.$route.params.taskId
      let docUnid = this.$route.query.docUnid;
      let processKey = this.$route.query.processKey;
      // processKey = "Gsfw"
      //docUnid = "DB09FD906DF345B1BE82BCCADA30325B"
      if(processKey!=null && processKey!='undefined' && processKey!=''){
        //如果processKey不为空 则表示为新建流程
        this.isEdit = 'edit'
        this.processKey = processKey
        this.loading = false
        return
      }
      if(taskId =='undefined' || taskId =='null' || taskId==null){
        taskId = ""
      }
	  this.taskId = taskId;
	  this.processKey = "Gsfw"
      judgeDocType(docUnid,taskId).then(response => {
        const code = response.code
        const openDpcType = response.data.openDocType
        console.log(response)
        if(code == "-1"){
          console.log(response.msg)
        }else{
          if(openDpcType == "todo"){
            //我的待办
            this.isEdit = 'read'
            this.docUnid = docUnid
          }else if(openDpcType == "drafts"){
            //我的草稿
            this.isEdit = 'edit'
          }else if(openDpcType == "apply"){
            //我的申请
            this.isEdit = 'read'
          }else if(openDpcType == "havaTodo"){
            //我的已办
            this.isEdit = 'read'
          }else if(openDpcType == "toread"){
            //我的待阅
             this.isEdit = 'read'
          }else if(openDpcType == "haveToread"){
            //我的已阅
            this.isEdit = 'read'
          }else{
            //错误
            console.log("异常")
            this.isEdit = 'error'
          }

        }
        this.loading = false
      }).catch((err) => {
        console.log(err)
        this.loading = false
      })

      /* if(taskId==null || taskId=='undefined' || taskId==''){
        //如果docUnid为空则表明是新表单
        if(docUnid==null || docUnid=='undefined' || docUnid==''){
          this.isEdit = true
        }else{
          //表明是草稿箱
          this.isEdit = true
          this.docUnid = docUnid
        }
      }else{
        //taskId不为空则是代办或者已办
        this.isEdit = false
      } */
    }
  }
</script>

<style>
</style>
